<?php
namespace App\Models;
use Redis;
class PushMessageNum{
  public $allNum=0;
  public $uid=0;
  public $redis;
  public $flag;
  public function __construct($uid){
  	$this->redis=new Redis();
	$this->redis->pconnect('localhost', 6379);
	$this->uid=$uid.'mes';
	if(!$this->redis->exists($this->uid)){
		//回复，关注我的人，点赞，关注我的人
		$this->redis->hmset($this->uid,array('reply'=>0,'followMy'=>0,'good'=>0));
		$this->flag='wtf';
	}else{
		$this->flag='wtf2';
	}
  }
  public function editPushMessageNum($type,$mode){
  	if($mode=='add'){
		switch ($type) { 
			case 'reply':
				$middle=$this->redis->hget($this->uid,'reply');
				return $this->redis->hset($this->uid,'reply',++$middle);
			break;
			case 'followMy':
				$middle=$this->redis->hget($this->uid,'followMy');
				return $this->redis->hset($this->uid,'followMy',++$middle);
			break;
			case 'good':
				$middle=$this->redis->hget($this->uid,'good');
				return $this->redis->hset($this->uid,'good',++$middle);
			break;
		}
  	}else if($mode=='delete'){
  		switch ($type) { 
			case 'followMy':
				$middle=$this->redis->hget($this->uid,'followMy');
				if($middle){
					return $this->redis->hset($this->uid,'followMy',--$middle);
				}
			break;
			case 'good':
				$middle=$this->redis->hget($this->uid,'good');
				if($middle){
					return $this->redis->hset($this->uid,'good',--$middle);
				}
			break;
		}
  	}
  	else{
		switch ($type) {
			case 'reply':
				return $this->redis->hset($this->uid,'reply',0);
			break;
			case 'followMy':
				return $this->redis->hset($this->uid,'followMy',0);
			break;
			case 'good':
				return $this->redis->hset($this->uid,'good',0);
			break;
		}

  	}
  }
}
